home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000089_icon-group-sender _Fri May 14 14:17:41 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 14 May 1993 12:27:28 MST
  2. Date: 14 May 1993 14:17:41 -0600 (CST)
  3. From: Chris Tenaglia - 257-8765 <TENAGLIA@mis.mcw.edu>
  4. Subject: parsing?
  5. To: icon-group@cs.arizona.edu
  6. Message-Id: <01GY60RE36O28WW2YZ@mis.mcw.edu>
  7. Organization: Medical College of Wisconsin (Milwaukee, WI)
  8. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
  11. Content-Transfer-Encoding: 7BIT
  12. Status: R
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14.  
  15. > From:    IN%"sboisen@bbn.com" 14-MAY-1993 11:03:31.80
  16. > To:    IN%"icon-group@cs.arizona.edu"
  17. > Subj:    string stripping
  18.  
  19. > This is so basic it's probably covered in the second week of Icon 101,
  20. > but since i never took the class ...
  21. > If i have a string and i want to strip out certain characters
  22. > (internal ones, so trim won't do it), i can do it like this
  23.  
  24. > # assume you want to remove hyphens and periods
  25. > full := "abc-def.ghi"
  26. > bare := ""
  27. > badchars := '-.'
  28.  
  29. > every c := !full do
  30. >    # test whether the intersection of c and badchars is empty
  31. >    if *(c ** badchars) = 0 then bare ||:= c
  32.  
  33. HOW ABOUT                       # procedure parse converts a string into
  34.                                 # a list of strings eliminating delimiters.
  35.   full := "abc-def.ghi"         # you can then concatenate them, sort them,
  36.   bare := ""                    # or do whatever you like. I put the delim-
  37.   badchars := '-.'              # iters into a cset which has the effect of
  38.                                 # collapsing them away.
  39.   new := parse(full,'-.')       #
  40.                                 #
  41.   write(image(new))             #
  42.   ["abc","def","ghi"]           #
  43.                                 #
  44. procedure parse(line,delims)
  45.   static chars
  46.   chars  := &cset -- delims
  47.   tokens := []
  48.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  49.   return tokens
  50.   end
  51.  
  52.  
  53. > But this seems awfully clunky, and i was disappointed that i couldn't
  54. > come up with a tighter way to do it: am i missing some more idiomatic
  55. > way to express this? Note there's two parts that i perceive as clunky:
  56. > the testing of whether c is in badchars (i suppose you could make
  57. > badchars a string and use find instead), and the control structure
  58. > with explicit generation and assignment to a new string.
  59. > Any Icon stylists want to offer some pointers on improvements? 
  60. > Sean
  61.  
  62.  
  63. Chris Tenaglia (System Manager) |  "The past explained,     
  64. Medical College of Wisconsin    |   the future fortold, 
  65. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  66. Milwaukee, WI 53226             |   Organon to The Doctor
  67. (414)257-8765                   |     
  68. tenaglia@mis.mcw.edu
  69.